#[allow(unused_imports)]
use std::rc::Rc;
#[allow(unused_imports)]
use std::cell::RefCell;
use student::Studentinfo;

#[allow(dead_code)]
enum List{
    Cons(i32, Rc<List>),
    Nil,
}

pub trait Print{
    fn print(&self);
}

pub struct Teacherinfo{
    pub name: String,
    pub age: u8,
    pub gender: String,
    pub position: String
}

impl Teacherinfo{
    pub fn teach(&self){
        println!("{} is teaching", self.name);
    }
    pub fn teach_student(&self,student: &Studentinfo){
        println!("{}正在教学生{}",self.name, student.name);
    }
}

pub fn print_teacher(teacher: &Teacherinfo){
    println!("{} is {} years old,性别:{},职位:{}", teacher.name, teacher.age
    , teacher.gender, teacher.position);
}


use std::thread;
use std::time::Duration;
use std::sync::{Arc, Mutex};

#[allow(unused)]
fn deal() {
   let v = vec![1, 2, 3,4,5,6,7,8,9,10];
   let handle = thread::spawn(move ||->Vec<i32> {    //如果这里不添加move关键字，编译会报错
       println!("Here's a vector: {:?}",v);
       //循环v,每次等待50毫秒
       for i in v.iter() {
           println!("T-1-waiting...:{}  ***(^^)",i);
           thread::sleep(Duration::from_millis(50));
       }
       v
   });

   //循环10次，每次等待20毫秒
   for x in 0..10 {
       println!("T-0-waiting...:{}",x);
       thread::sleep(Duration::from_millis(20));
   }
   let p=handle.join().unwrap();
   println!("It's back!{:?}",p);
}
#[allow(unused)]
fn fn_mutex(){
    let counter = Arc::new(Mutex::new(0));
    let mut handles = vec![];
    for _ in 0..10 {
        let c = Arc::clone(&counter);
        let handle = thread::spawn(move || {
            let mut num = c.lock().unwrap();
            *num += 1;
            println!("线程{:?}正在执行,得到{}", thread::current().id(),*num);
        });
        handles.push(handle);
    }
    for handle in handles {
        handle.join().unwrap();
    }
    println!("Result: {}", *counter.lock().unwrap());
}


